package movee.spring.app.template.domain.dao;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.io.Serializable;

/**
 *
 *
 * @author movee
 */
@Data
@NoArgsConstructor
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@SuperBuilder
@DynamicUpdate
@DynamicInsert
@Entity
@Table(name = "t_item", indexes = {
        @Index(name = "idx_name", columnList = "name"),
        @Index(name = "idx_creator", columnList = "creator"),
        @Index(name = "idx_updater", columnList = "updater"),
        @Index(name = "idx_create_time", columnList = "create_time"),
        @Index(name = "idx_update_time", columnList = "update_time")
})
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id",
        scope = JoinedItemDao.class)
@JsonIgnoreProperties(value = { "hibernateLazyInitializer", "handler" })
public class JoinedItemDao extends BaseItemDao implements Serializable {


    /**
     * order id（多对一）
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id", referencedColumnName = "id")
    @JsonIdentityReference(alwaysAsId = true)
    private JoinedOrderDao order;

}
